package Pages;


import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.Closeable;
import java.text.DateFormat;
import java.text.SimpleDateFormat;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;





public class MainPageInterface extends JFrame implements ActionListener{
	
	JLabel ResimTutucu1 = new JLabel();// MBS Resim tutucu
	ImageIcon Resim1 = new ImageIcon(getClass().getResource("MBS.png"));//MBS Resim /// Bu Resim Daha iyisiyle deï¿½iï¿½tirilecektir
	
	JPanel[] panel;
	JButton basicInfoButton = new JButton("Temel Bilgiler");
    JButton reportButton = new JButton("İki Tarih Arası Raporlar");
    JButton dailyProcessesButton = new JButton("Günlük İşler");
    JButton specialReportsButton = new JButton("Özel Raporlar");
    JButton exitButton = new JButton("Exit");
    
    ///////////////////////////  For time
    public JLabel show_time = new JLabel("Show Time");
    public JLabel Show_date = new JLabel("Show Date");

    DateFormat dateFormat2 = new SimpleDateFormat("h:mm:ss a");
    java.util.Date date2;
    long msec;
	//////////////////////////////
    
	public MainPageInterface() {
		// TODO Auto-generated constructor stub
	super("Anasayfa");
	this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	GridLayout experimentLayout = new GridLayout(10,5);
	setLayout(experimentLayout);
	
	JPanel panel[]=new JPanel[50];
	for(int i=0;i<50;i++){
		panel[i]=new JPanel();
		add(panel[i]);
	}
	
	//i,7-16-18-21-23
		
		ResimTutucu1.setIcon(Resim1);
		panel[7].add(ResimTutucu1);
		
		
		basicInfoButton.setPreferredSize(new Dimension(200,40));
		basicInfoButton.addActionListener(this);
		panel[16].add(basicInfoButton);
	
		reportButton.setPreferredSize(new Dimension(200,40));
		reportButton.addActionListener(this);
		panel[18].add(reportButton);
		
		dailyProcessesButton.setPreferredSize(new Dimension(200,40));
		dailyProcessesButton.addActionListener(this);
		panel[21].add(dailyProcessesButton);
	
		specialReportsButton.setPreferredSize(new Dimension(200,40));
		specialReportsButton.addActionListener(this);
		panel[23].add(specialReportsButton);
		
		//exitButton.setPreferredSize(new Dimension(170,40));  //exit button hocaya sor!!!!!!!!
		//exitButton.addActionListener(this);
		//panel[27].add(exitButton);
		
		////////////////////////////bundan sonram Date / Time
		
		Font f;
        f = new Font("SansSerif", Font.PLAIN, 13);
        
        DateFormat dateFormat = new SimpleDateFormat("EEEEEEEEE: dd MMMMMMMMM, yyyy.");
        java.util.Date date = new java.util.Date();
        String dateTime = dateFormat.format(date);
        
        Show_date = new JLabel(dateTime);
        Show_date.setFont(f);
        panel[13].add(Show_date); 
        
        show_time= new JLabel("");
        updateDateTime();
        show_time.setFont(f);
        panel[13].add(show_time);

	 pack();
	}

	@Override
	public void actionPerformed(ActionEvent event) {
	if (event.getSource() == basicInfoButton) {
		javax.swing.SwingUtilities.invokeLater(new Runnable() {
            public void run() {
    	        new BasicInformationPage().runTest(); 
          								
            }
        });
            /////////////////////////2.interface
        }
        else if (event.getSource() == dailyProcessesButton) {
        	//remove(getContentPane());
        	javax.swing.SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                	new DailyProcessesPage().runTest();
                }
            });
           
        }else if (event.getSource() == reportButton) {
        	
        	javax.swing.SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                	new ReportsByDate().runTest();
                }
            });
           
        }

	}
	private void updateDateTime()
    {
    Thread th = new Thread(new Runnable()
        {
        public void run()
            {
            while(true)
                {
                date2 = new java.util.Date();
                msec = date2.getTime();
                //msec += (11.5)*60*60*1000L;
                date2.setTime(msec);
                String dateTime = dateFormat2.format(date2);
                show_time.setText(dateTime);
                show_time.updateUI();
                }
            }
        });
    th.start();
    }
}
